package org.petstore.web.servlet;

import org.petstore.domain.Account;
import org.petstore.service.AccountService;
import org.petstore.service.CatalogService;
import org.petstore.service.impl.AccountServiceImpl;
import org.petstore.service.impl.CatalogServiceImpl;
import org.petstore.web.servlet.util.MyUtil;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class FindProductServlet extends HttpServlet {

    CatalogService catalogService = MyUtil.getApplicationContext().getBean("catalogService", CatalogService.class);

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        response.setContentType("text/html;charset=utf-8");
//        request.setCharacterEncoding("utf-8");
//        //获取搜索框输入的内容
//
//        keyword = new String(keyword.getBytes("iso-8859-1"), "utf-8");
//        //向server层调用相应的业务
//
//        //返回结果
//        response.getWriter().write(res);
        String keyword = request.getParameter("keyword");
        response.setContentType("text/plain");
        PrintWriter out = response.getWriter();
        String res = catalogService.findProductListAjax(keyword);
        out.print(res);
        out.flush();
        out.close();
    }

//    该页面主要用于后期的鼠标移动监听事件，使得鼠标移动到图片上时会出现相应的内容。暂时没作用  2021.11.2
}
